﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace CharacterCreation.Business.Calculations {
    public static class Dice {
        private static Random rnd = new Random();

        public static int D6() {
            return rnd.Next(1, 7);
        }

        public static int D8() {
            return rnd.Next(1, 9);
        }

        public static int D20() {
            return rnd.Next(1, 21);
        }

        public static int D100() {
            return rnd.Next(1, 101);
        }

        public static int Statistic() {

            int stat = D6() + D6() + D6() + D6();
            if (stat > 20) {
                int exception = D6();
                if (exception == 6) exception += D6();

                stat += exception;
            }

            return stat;
        }

        public static List<int> Statistics(int minValue) {
            List<int> statList = new List<int>();
            int total = 0;

            while (total < minValue) {
                statList = new List<int>();
                for (int i = 0; i < 10; ++i)
                    statList.Add(Statistic());

                total = statList.Sum();
            }

            return statList;
        }
    }
}
